﻿using Knife.Core.DataBase;
using Knife.Core.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Knife.Core.Template
{
    public class BaseTemplateDB<T> where T : BaseEntity
    {
        private MapperEntity mapperEntity;
        public BaseTemplateDB()
        {
            mapperEntity = EntityMapper.GetInstance().GetMapperEntity(typeof(T));
        }
        public void Insert(T entity)
        {
            CommonExecute.Insert(entity);
        }
        public void Delete(string rowid)
        {
            CommonExecute.Delete<T>(rowid);
        }
        public void BatchDelete(List<string> rowidList)
        {
            foreach (var rowid in rowidList)
            {
                CommonExecute.Delete<T>(rowid);
            }
        }
        public void Update(T entity)
        {
            CommonExecute.Update(entity);
        }
        public void BatchUpdate(List<T> entityList)
        {
            foreach (var entity in entityList)
            {
                CommonExecute.Update(entity);
            }
        }
        public T SelectOne(string row_id)
        {
            return CommonQuery.SelectOne<T>(mapperEntity.MapTableName, "*", "row_id", row_id);
        }
        public Page SelectPage(string strColumns, string strWhere, string strOderby, int pageIndex, int pageSize, Dictionary<string, object> paramList)
        {
            return CommonQuery.SelectPage(mapperEntity.MapTableName, strColumns, strWhere, strOderby, pageIndex, pageSize, paramList);
        }
        public List<T> SelectPageList(string strColumns, string strWhere, string strOderby, int pageIndex, int pageSize, Dictionary<string, object> paramList)
        {
            return CommonQuery.SelectPageList<T>(mapperEntity.MapTableName, strColumns, strWhere, strOderby, pageIndex, pageSize, paramList);
        }
        public List<T> SelectList(string strColumns, string strWhere, string strOderby, Dictionary<string, object> paramList)
        {
            return CommonQuery.SelectList<T>(mapperEntity.MapTableName, strColumns, strWhere, strOderby, paramList);
        }
        public int SelectCount(string strWhere, Dictionary<string, object> paramList)
        {
            return CommonQuery.SelectCount(mapperEntity.MapTableName, strWhere, paramList);
        }
    }
}
